Skip to content

refactor: PlatformRegistry pattern#18

Draft
jaredperreault-okta wants to merge 5 commits intomasterfrom
jp-platform-registry
Draft

refactor: PlatformRegistry pattern#18
jaredperreault-okta wants to merge 5 commits intomasterfrom
jp-platform-registry

Conversation

@jaredperreault-okta
Copy link
Contributor

No description provided.

Comment on lines +9 to +12
export interface PlatformDependencies {
TimeCoordinator: TimeCoordinator;
DPoPSigningAuthority: DPoPSigningAuthority;
}
Copy link

@alexchen-okta alexchen-okta Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking ahead, just curious if is there anything currently in the plan to extend this and support any specific additional global dependencies? i.e. there any scope for telemetry or a logger for errors or certain oauth operations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both Telemetry and Loggers are great examples of things we could put in here. There probably won't be specific OAuth operations, but perhaps singletons to enable OAuth operations, like the DPoPSigningAuthority for example.

I will probably add things here I expect to get implemented at a platform level, like TokenStorage. The advantage is the default In-Memory Token storage impl won't be included in the bundle

Comment on lines +20 to +40
* For example, the {@link TimeCoordinator} should be globally available to be a
* centralized entity to perform all time calculations. Registering the {@link TimeCoordinator}
* as a {@link Platform} dependency enables consumers to access the {@link TimeCoordinator} via
*
* @example
* ```
* import { Platform } from '@okta/auth-foundation';
* const currentTime = Platform.TimeCoordinator.now();
* ```
*
* To enable tree-shaking and prevent including default implementations (bundle bloat) which
* will be instanceously overwritten, default implemenations can be selectively included.
*
* @remarks
* Use `import * from '@okta/auth-foundation'` for standard usage, including all default platform
* dependency implementations.
*
* Use `import * from '@okta/auth-foundation/core'` for deeper customizations of platform dependencies,
* this does not include any default implementations. {@link PlatformRegistryError} will be thrown if
* a dependency is used before an implementation is provided
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the usage is very clearly explained here

Comment on lines +16 to +19
/**
* A singleton registry of globally-available singleton dependencies which can
* provide platform-specific default implementations and enable overriding as needed
*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first time i read the class name PlatformRegistry, i assumed more of a registry of platforms i.e. browsers/node rather than a registry of dependencies that can be overriden to support different platforms. i can't come up with a better name myself but just wanted to give feedback in case you had a better name in mind

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is hard

* ```
*
* To enable tree-shaking and prevent including default implementations (bundle bloat) which
* will be instanceously overwritten, default implemenations can be selectively included.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo on implemenations


/** @internal */
export const DefaultDPoPSigningAuthority: DPoPSigningAuthority = new DPoPSigningAuthorityImpl(new DPoPStorage.MemoryStore());
/** @internal - Use `Platform.DPoPSigninAuthority instead */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing closing backtick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants